@import "../common/vars.scss";
@import "../mixins/mixins.scss";
@include create(table) {
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    flex: 1;
    width: 100%;
    max-width: 100%;
    background-color: $color-white;
    font-size: 14px;
    color: $table-text-color;

    @include m(page){
      position: relative;
      width: 100%;
      padding: 7px 7px 0;
      border-top: $table-border;
      height: 40px;
    }


    @include e(expand-icon){
      position: relative;
      cursor: pointer;
      color: $color-text-primary;
      font-size: 14px;
      transition: transform .2s ease-in-out;
      height: 20px;
      display: inline-block;
      width: 14px;
    }
    & .caret-wrapper{
      display: inline-flex;
      flex-direction: column;
      align-items: center;
      height: 22px;
      width: 24px;
      vertical-align: middle;
      cursor: pointer;
      overflow: initial;
      position: relative;
    }
    & .ascending{
      .sort-caret.ascending{
        border-bottom-color: $color-primary-light-1;
      }
    }
    & .descending{
      .sort-caret.descending{
        border-top-color: $color-primary-light-1;
      }
    }
    & .sort-caret{
      width: 0;
      height: 0;
      border: 5px solid transparent;
      position: absolute;
      left: 7px;
      &.descending{
        border-top-color: #c0c4cc;
        bottom: 1px;
      }
      &.ascending{
        border-bottom-color: #c0c4cc;
        top: -2px;
      }
    }

    // 数据为空
    @include e(empty-block) {
        min-height: 60px;
        text-align: center;
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    @include e(empty-text) {
        width: 50%;
        color: $color-text-secondary;
    }


    thead {
        color: $table-header-color;
        font-weight: 500;
    
        &.is-group {
          th {
            background: $background-color-base;
          }
        }
    }
    th, td {
        padding: 12px 0;
        min-width: 0;
        box-sizing: border-box;
        text-overflow: ellipsis;
        vertical-align: middle;
        position: relative;
        text-align: left;

        @include when(center) {
            text-align: center;
        }
      
        @include when(right) {
            text-align: right;
        }

        &.is-hidden {
            > * {
              visibility: hidden;
            }
        }

        &.gutter {
            width: 15px;
            border-right-width: 0;
            border-bottom-width: 0;
            padding: 0;
        }
    }

    th {
        white-space: nowrap;
        overflow: hidden;
        user-select: none;
        background-color: $table-header-background;
        div {
          display: inline-block;
          padding-left: 10px;
          padding-right: 10px;
          line-height: 40px;
          box-sizing: border-box;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
    
        > .cell {
          position: relative;
          word-wrap: normal;
          text-overflow: ellipsis;
          display: inline-block;
          vertical-align: middle;
          box-sizing: border-box;
        //   width: 100%;
          &.highlight {
            color: $color-primary;
          }
        }
    }

    td {
        div {
          box-sizing: border-box;
        }
    
        &.gutter {
          width: 0;
        }
    }

    .cell {
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: normal;
        word-break: break-all;
        line-height: 23px;
        padding-left: 10px;
        padding-right: 10px;
    
        &.aiui-tooltip {
          white-space: nowrap;
          min-width: 50px;
        }
        & .aiui-table-expand-icon{
          width: 14px;
          height: 14px;
          text-align: center;
          transition: transform .3s;
        }
    }
    // 拥有多级表头
  @include m((group, border)) {
    border: $table-border;

    @include share-rule(border-pseudo) {
      content: '';
      position: absolute;
      background-color: $table-border-color;
      z-index: 1;
    }

    // 表格右部伪 border
    &::after {
      @include extend-rule(border-pseudo);
      top: 0;
      right: 0;
      width: 1px;
      height: 100%;
    }

    & .aiui-table-wrapper .aiui-table-fixed-right-patch{
        background: $background-color-base;
    }
  }

  // 表格底部伪 border，总是有的
  &::before {
    @include extend-rule(border-pseudo);
    left: 0;
    bottom: 0;
    width: 100%;
    height: 1px;
  }

  // table--border
  @include m(border) {
    border-right: none;
    border-bottom: none;

    &.aiui-loading-parent-relative {
      border-color: transparent;
    }

    thead th{
      background: $background-color-base;
    }

    th, td {
      border-right: $table-border;

      &:first-child .cell {
        padding-left: 10px;
      }

      th.gutter:last-of-type {
        border-bottom: $table-border;
        border-bottom-width: 1px;
      }
    }

    th.gutter:last-of-type {
      border-bottom: $table-border;
      border-bottom-width: 1px;
    }

    & th {
      border-bottom: $table-border;
    }

    
  }
  @include e((fixed, fixed-right)) {
    position: absolute;
    top: 0;
    left: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    box-shadow: $table-fixed-box-shadow;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1px;
      background-color: $border-color-lighter;
      z-index: 4;
    }
  }
  @include e(fixed-right) {
    top: 0;
    left: auto;
    right: 1px;
    .aiui-table-fixed-header-wrapper,
    .aiui-table-fixed-body-wrapper{
      left: auto;
      right: 0;
    }
  }

  @include e(fixed-right-patch) {
    position: absolute;
    top: -1px;
    right: 0;
    background-color: $color-white;
    border-bottom: $table-border;
  }

  @include m(fixed-body-wrapper) {
    left: 0;
    overflow: hidden;
    z-index: 3;
  }

  tr {
    background-color: $color-white;

    input[type="checkbox"] {
      margin: 0;
    }

    &.is-open .cell .aiui-table-expand-icon{
      transform: rotate(90deg);
    }
  }

  th.is-leaf, td {
    border-bottom: $table-border;
  }

  @include e((header-wrapper, body-wrapper)) {
    width: 100%;
  }

  @include e(header-wrapper){
    overflow: hidden;
    position: relative;
    background: $background-color-base;
    border-bottom: $table-border;
    & table{
      margin-bottom: -1px;
    }
  }

  @include e(body-wrapper) {
    overflow: auto;
    position: relative;
  }

  .cell{
    min-width: 40px !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
  @include e(body){
    td>.cell{
      font-size: 14px;
      font-weight: 400;
      color: $color-text-primary;
    }
  }
}